package router

import (
	"controllers/bundlecontroller"
	"controllers/categorycontroller"
	"controllers/productcontroller"
	"controllers/serchcontroller"
	"controllers/usercontroller"
	"github.com/gin-gonic/gin"
	"net/http"
	"router/middleware"
)

func Load(g *gin.Engine, mw ...gin.HandlerFunc) *gin.Engine {
	// Middlewares.
	g.Use(gin.Recovery())
	//g.Use(middleware.NoCache)
	//g.Use(middleware.Options)
	//g.Use(middleware.Secure)
	g.Use(mw...)
	// 404 Handler.
	g.NoRoute(func(c *gin.Context) {
		c.String(http.StatusNotFound, "The incorrect API route.")
	})
	g.POST("/login", usercontroller.Login)
	g.POST("/sendRgSmsCode", usercontroller.SendRegisterSmsCode)
	g.POST("/register", usercontroller.Register)
	g.POST("/resetPassword", usercontroller.ResetPassword)
	g.POST("/category/getList", categorycontroller.GetCategoryList)
	g.POST("/product/getList", productcontroller.GetProductList)
	g.POST("/banner/getList", serchcontroller.GetBannerList)
	u := g.Group("/bundle")
	i := u.Use(middleware.AuthMiddleware())
	i.POST("/bundle", bundlecontroller.Bundle)
	return g
}
